define(['./../initial', './../directive/infoModal'], function () {
    var app = angular.module('App.home');
    app.factory('showInfoModal', ['$q', '$timeout', '$compile', "$rootScope",
        function ($q, $timeout, $compile, $rootScope) {
            function showMsg(option) {

                var backOption = {
                    title: "",
                    content: "",
                    scope: $rootScope,
                    onConfirm: function () {

                    },
                    onCancel: function () {

                    }
                };
                option = angular.extend(backOption, option);

                var exist = document.querySelector('#infoModal');
                if (exist) {
                    exist.remove();
                }

                var element = document.createElement('div');
                element.setAttribute('data-info-Modal', "");
                element.setAttribute('data-title', option.title);
                element.setAttribute('data-content', option.content);
                element.setAttribute('data-button', option.button || 1);
                document.body.appendChild(element);
                option.scope.onConfirm = (function (scope) {
                    return function () {
                        option.onConfirm();
                        delete scope.onConfirm;
                    };
                })(option.scope);
                option.scope.onCancel = (function (scope) {
                    return function () {
                        option.onCancel();

                        delete scope.onConfirm;
                    };
                })(option.scope);
                element.setAttribute('data-on-confirm', "onConfirm");
                element.setAttribute('data-on-Cancel', "onCancel");
                var directive = angular.element(element);
                $compile(directive)(option.scope);
            }
            return showMsg;
        }
    ]);
});
